from django.template import Library
from django.conf import settings
import copy
register = Library()


@register.inclusion_tag("tag/wl_menu.html")
def wl_menu(request):
    # 1.读取当前用户的登录信息
    # print(request.wl_user.role)
    # print(request.path_info)

    # 2. 获取菜单信息
    user_menu_list = copy.deepcopy(settings.WL_MENU[request.wl_user.role])

    for item in user_menu_list:
        for child in item['children']:
            # if child['url'] == request.path_info:
            if child['name'] == request.wl_user.menu_name:
                child['class'] = 'active'
    return {'menu_list': user_menu_list}
